package com.controller;

import com.entity.Employee;
import com.github.pagehelper.PageInfo;
import com.service.EmployeeService;
import com.util.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author cj
 * @date 2019/10/12
 */

@WebServlet("/elementpage")
public class ElementUiPageServlet extends HttpServlet {

  @Override
  protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/json;charset=UTF-8");
    EmployeeService employeeService = new EmployeeService();
    //当前页
    int pageNum = Integer.parseInt(req.getParameter("page"));
    int pageSize = Integer.parseInt(req.getParameter("pagesize"));
    List<Employee> emps = employeeService.getEmpsByPageHelper(pageNum, pageSize);
    PageInfo<Employee> pageInfo = new PageInfo<>(emps, 3);
    String s = JsonUtil.object2String(pageInfo);
    resp.getWriter().println(s);
  }
}
